package org.example.viteVantDemo;

import org.example.viteVantDemo.cache.ServerMemoryCache;
import org.example.viteVantDemo.mapper.UserMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
@MapperScan("org.example.viteVantDemo.mapper")
public class Application implements InitializingBean {
    @Autowired
    private UserMapper userMapper;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void afterPropertiesSet() {
        String version = userMapper.queryParam(ServerMemoryCache.SERVER_VERSION);
        ServerMemoryCache.addCache(ServerMemoryCache.SERVER_VERSION, Integer.parseInt(version));
    }

    /**
     *  获取当前局数版本
     *
     * @return
     */
    public static Integer getVersion() {
        return ServerMemoryCache.getIntValue(ServerMemoryCache.SERVER_VERSION);
    }
}
